package com.gintama.base.enums;



/**
 * The interface Base result code.
 *
 * @author hao.hu
 * @since 2020 /3/19
 */
public interface BaseResultCode {

	/**
	 * 默认成功编码
	 */
	String OK_CODE = "0000";
	/**
	 * The constant OK_MSG.
	 */
	String OK_MSG = "success";

	/**
	 * 默认失败编码
	 */
	String ERROR_CODE = "9999";
	/**
	 * The constant ERROR_MSG.
	 */
	String ERROR_MSG = "error";

	/**
	 * 处理结果的状态码 参考 {@link Result}
	 *
	 * @return code string
	 */
	String code();

	/**
	 * 处理结果的信息 参考 {@link Result}
	 *
	 * @return msg string
	 */
	String msg();

	/**
	 * Series result code series.
	 *
	 * @return ResultCodeSeries result code series
	 */
	default ResultCodeSeries series() {
		return ResultCodeSeries.value(this);
	}

	/**
	 * Whether this status code is in the result code series {@link ResultCodeSeries#PARAM_ERROR}. This is a shortcut
	 * for checking the value of {@link #series()}.
	 *
	 * @return the boolean
	 * @see #series() #series()
	 */
	default boolean is1xxxParamError() {
		return ResultCodeSeries.PARAM_ERROR == this.series();
	}

	/**
	 * Whether this status code is in the result code series {@link ResultCodeSeries#BUSINESS_ERROR}. This is a shortcut
	 * for checking the value of {@link #series()}.
	 *
	 * @return the boolean
	 * @see #series() #series()
	 */
	default boolean is2XxxBusinessError() {
		return ResultCodeSeries.BUSINESS_ERROR == this.series();
	}

	/**
	 * Whether this status code is in the result code series {@link ResultCodeSeries#PROGRAM_ERROR}. This is a shortcut
	 * for checking the value of {@link #series()}.
	 *
	 * @return the boolean
	 * @see #series() #series()
	 */
	default boolean is3XxxProgramError() {
		return ResultCodeSeries.PROGRAM_ERROR == this.series();
	}

	/**
	 * Whether this status code is in the result code series {@link ResultCodeSeries#NETWORK_ERROR}. This is a shortcut
	 * for checking the value of {@link #series()}.
	 *
	 * @return the boolean
	 * @see #series() #series()
	 */
	default boolean is4XxxNetworkError() {
		return ResultCodeSeries.NETWORK_ERROR == this.series();
	}

	/**
	 * Is ok boolean.
	 *
	 * @param code the code
	 * @return the boolean
	 */
	static boolean isOk(String code) {
		return OK_CODE.equals(code);
	}

	/**
	 * Is error boolean.
	 *
	 * @param code the code
	 * @return the boolean
	 */
	static boolean isError(String code) {
		return !isOk(code);
	}

}
